package com.rich.broker.service.impl;

import com.rich.broker.mapper.TbWantMapper;
import com.rich.broker.service.WantService;
import com.rich.broker.service.feign.UserMapper;
import com.rich.broker.vo.WantVo;
import com.rich.common.entity.TbUser;
import com.rich.common.entity.TbWant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Package: com.rich.house.service.impl
 * @Author: 张dy
 * @Date: Created in 2021/8/13 下午 7:36
 */
@Service
public class WantServiceImpl implements WantService {

    @Autowired
    private TbWantMapper wantMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<TbWant> findAll() {
        return wantMapper.findAll();
    }

    @Override
    public List<WantVo> findByStatus(TbWant want, String status) {
        //求租求购的信息
        List<WantVo> byStatus = wantMapper.findByStatus(want, status);
        //遍历把用户信息一起返回
        byStatus.forEach((tbWant)->{
            //查询发布次 求租求购人的信息
            TbUser user = userMapper.findById(tbWant.getUid());
            tbWant.setUser(user);
        });
        return byStatus;
    }
}
